<?php

namespace app\common\job;

use DOMDocument;
use DOMXPath;
use GuzzleHttp\Client;
use think\Exception;
use think\queue\Job;
use app\common\reptile;

/**
 * create by PhpStorm 2025/8/1 14:24
 * szyc.com app\common\job@ReptileJob
 * 行止之行 <xingzhi8711@gmail.com>
 * 爬虫任务
 */
class ReptileJob
{
    public $method;
    public function fire(Job $job, $data)
    {
        try {
            $website = $data['website'];
            $method=str_replace(["https://","http://"],"",$website);
            $method=str_replace([".","/"],"_",$method);
            setLog(__METHOD__,$method);
            $this->method=$method;
            $className="app\common\\reptile\\".$this->method;
            $cls=new $className();
            if (method_exists($className,"article")) {
                $cls->initArticle();
            }
            if($cls->init()){
                $job->delete();
            }elseif($job->attempts() > 3){
                $job->delete();
            }else{
                $job->release();
            }
        }catch (\Exception $e){
            $job->delete();
        }

    }

}